import { setToken, getToken, removeToken } from "../../utils/auth.js";
const state = {
  TokenData: "",
  BtnPermission: []
};
//内部方法 fn:(state, view) => {}
const mutations = {
  SET_TOKENDATA: (state, value) => {
    state.TokenData = value;
  },
  SET_BTNPERMISSION: (state, value) => {
    state.BtnPermission = value;
  }
};
//对外方法 fn({ commit },value)
const actions = {
  setTokenData({ commit, state }, data) {
    return new Promise(resolve => {
      commit("SET_TOKENDATA", data);
      setToken(data);
      resolve();
    });
  },
  resetToken({ commit, state }, data) {
    return new Promise(resolve => {
      commit("SET_TOKENDATA", "");
      removeToken();
      resolve();
    });
  },
  setBtnPermission({ commit, state }, data) {
    return new Promise(resolve => {
      commit("SET_BTNPERMISSION", data);
      resolve();
    });
  }
};
const getters = {
  TokenData: state => state.TokenData || getToken(),
  BtnPermission: state => state.BtnPermission
};

/**
 * @description 页签相关
 */
export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
